/*
 * XXX
 */

package edu.uhcl.csci4838.group3.view;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;
import edu.uhcl.csci4838.group3.R;
import edu.uhcl.csci4838.group3.database.BackpackEduDatabaseHelper;
import edu.uhcl.csci4838.group3.test.DatabaseTest;
import edu.uhcl.csci4838.group3.test.TestCodeForStart;
import android.content.SharedPreferences;

/**
 * XXX
 * 
 * @author Chris Bruce
 *
 */
public class SplashActivity extends Activity {
	
	/**
	 * XXX
	 * Handler class implementation to handle the message
	 * 
	 * @author Chris Bruce
	 *
	 */
	private class SplashHandler extends Handler {
		
		/**
		 * XXX
		 * This method is used to handle received messages
		 * 
		 * @param msg
		 */
		/* 
		 * (non-Javadoc)
		 * 
		 * @see android.os.Handler#handleMessage(android.os.Message)
		 */
		@Override
		public void handleMessage(final Message msg) {
			// switch to identify the message by its code
			switch (msg.what) {
				default:
				case 0:
					super.handleMessage(msg);
					
					// Create an intent to start the new activity.
					// Our intention is to start MainActivity
					final Intent intent = new Intent();
					intent.setClass(SplashActivity.this,
							HomeActivity.class);
					SplashActivity.this.startActivity(intent);
					// finish the current activity
					SplashActivity.this.finish();
			}
		}
	}
	
	/**
	 * XXX
	 * Called when the activity is first created.
	 * 
	 * @param savedInstanceState
	 */
	/* 
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(final Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		//////////// TODO Remove this!!! /////////////////////////////////
		
		TestCodeForStart.onReceive(this); 
		/////////////////////////////////////////////////////////////////
		
		this.setRequestedOrientation(
				ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		// Set the layout for this activity
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.activity_splash);
		// Create a Message object
		final Message msg = new Message();
		// Assign a unique code to the message.
		// Later, this code will be used to identify the message in Handler
		// class.
		msg.what = 0;
		

		// Create an object of type SplashHandler
		final SplashHandler mHandler = new SplashHandler();
		// Send the message with a delay of 3 seconds(3000 = 3 sec).
		mHandler.sendMessageDelayed(msg,
				1000); // TODO change to 2000 - 3000 when done
	}
}
